package com.lagou;/*
 *Author:cxz
 *@Date:${Date}
 */

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/*
@ClassName EmailController

*@Description
*@Author cxz
*@Date 2020/7/8 15:54
*Version V1.0
*/
@RestController
@RequestMapping("/email")
public class EmailController {

    @Value("${spring.mail.username}")
    private String from;
    @Autowired
    JavaMailSender javaMailSender;

    @RequestMapping("/{email}/{code}")
    public String sendSimpleMail(@PathVariable("email") String email, @PathVariable("code") String code) {
        SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
        simpleMailMessage.setFrom(from);
        simpleMailMessage.setTo(email);
        simpleMailMessage.setSubject("验证码");
        simpleMailMessage.setText(code + "");
        javaMailSender.send(simpleMailMessage);
        return "success";
    }
}
